#include"process.h"

#define SIZE 101
#define STYLE '='

void FlushProcess(double curr,double total)
{
  if(curr > total) curr = total;
  //计算比率
  double rate = curr / total * 100;
  int cnt = (int)rate;
  char processbuff[SIZE];
  memset(processbuff,'\0',sizeof(processbuff));

  int i = 0;
  for(; i < cnt; i++) processbuff[i] = STYLE;
  
  static const char* label = "|/-\\";
  int len = strlen(label);
  static int index = 0;//用来标记label数组的位置
  printf("[%-100s][%.1lf%%][%c]\r",processbuff,rate,label[index++]);
  fflush(stdout);
  index %= len;

  if(curr >= total) printf("\n");
}





















//无法使用，因为没有结合实际的示例来写
//void process()
//{
//  char processbuff[SIZE];
//  memset(processbuff,'\0',sizeof(processbuff));
//  int cnt = 0;
//  const char* label ="|/-\\";//定义旋转轮盘
//  int len= strlen(label);
//  while(cnt <= 100)
//  {
//    printf("[%-100s][%d%%][%c]\r",processbuff,cnt,label[cnt%len]);
//    fflush(stdout);
//    processbuff[cnt++] = STYLE;
//    usleep(30000);
//  
//  }
//  printf("\n");
//}
